package com.cafe.case5;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.alibaba.ttl.TtlRunnable;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TtlDemo {
    public static void main(String[] args) throws InterruptedException {
        AppContext.USER_NAME.set("Main1");

        System.out.println("At Start, USER_NAME:" + AppContext.USER_NAME.get());

        ExecutorService pool = Executors.newFixedThreadPool(1);

        Runnable runnableA = new RunnableTask("TaskA");
        TtlRunnable ttlRunnableA = TtlRunnable.get(runnableA);
        pool.submit(ttlRunnableA);

        Thread.sleep(100);

        Runnable runnableB = new RunnableTask("TaskB");
        TtlRunnable ttlRunnableB = TtlRunnable.get(runnableB);
        pool.submit(ttlRunnableB);

        Thread.sleep(1000);
        System.out.println("At End, USER_NAME:" + AppContext.USER_NAME.get());
//        AppContext.USER_NAME.set("Main2");
//        pool.submit(ttlRunnableA);

    }
}
